﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tetris
{
    class Drawer
    {

        public void FrameDrawer(GameField field)
        {
            int width = field.Width + 2;
            int height = field.Height + 2;
            int xPosition = field.StartX - 1;
            int yPosition = field.StartY - 1;
            char[,] consoleFrame = new char[height, width];
            for (int i = 0; i < consoleFrame.GetLength(0); i++)
            {
                for (int j = 0; j < consoleFrame.GetLength(1); j++)
                {
                    if (i == height - 1 || j == 0 || j == width - 1)
                    {
                        consoleFrame[i, j] = '#';
                    }
                    else
                    {
                        consoleFrame[i, j] = ' ';
                    }
                }
            }

            for (int i = 0; i < consoleFrame.GetLength(0); i++)
            {
                Console.SetCursorPosition(xPosition, yPosition++);
                for (int j = 0; j < consoleFrame.GetLength(1); j++)
                {
                    Console.Write(consoleFrame[i,j]);
                }
            }
        }

        public void DrawFigure(Node node)
        {
            Console.ForegroundColor = node.nodeColor;
            Console.SetCursorPosition(node.XNode, node.YNode);
            Console.WriteLine('@');
            Console.ForegroundColor = ConsoleColor.White;
        }

        public void ClearFigure(Node node)
        {
            Console.SetCursorPosition(node.XNode, node.YNode);
            Console.WriteLine(' ');
        }

        public void DrawTheScore(GameField field, int currPoints, int total)
        {
            Console.SetCursorPosition(field.StartX + field.Width + 10, field.StartY + 1);
            Console.WriteLine("Current coins\t Total Score");
            Console.SetCursorPosition(field.StartX + field.Width + 10, field.StartY + 2);
            Console.WriteLine("{0}\t\t {1}", currPoints, total);
        }

        public void DrawTheNextFigure (GameField field, Node node)
        {
            Console.ForegroundColor = node.nodeColor;
            Console.SetCursorPosition(node.XNode + field.Width/2 + 10, node.YNode + 5);
            Console.WriteLine('@');
            Console.ForegroundColor = ConsoleColor.White;
        }

        public void ClearTheNextFigure(GameField field, Node node)
        {
            Console.SetCursorPosition(node.XNode + field.Width / 2 + 10, node.YNode + 5);
            Console.WriteLine(' ');
        }

    }
}
